package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.EmailBean;
import com.project.bean.InboxBean;
import com.project.mapper.IEmailMapper;
import com.project.mapper.IEmployeeMapper;
import com.project.mapper.IInboxMapper;
import com.project.service.IInboxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
@Service
@Transactional
public class IInboxServiceImpl  implements IInboxService {
    @Autowired
    private IInboxMapper inboxMapper;
    @Autowired
    private IEmailMapper emailMapper;
    @Autowired
    private IEmployeeMapper emMapper;
    @Override
    public IPage<InboxBean> cutByItem(Integer pageNO, Integer receiverId, String head, LocalDate startDate, LocalDate endDate) {

        return inboxMapper.cutByItem(new Page<>(pageNO,3),receiverId,head,startDate,endDate);
    }

    @Override
    public EmailBean findById(Integer inboxId) {
        InboxBean inboxBean = inboxMapper.selectById(inboxId);
        inboxBean.setIsRead("已读");
        inboxMapper.updateById(inboxBean);
        EmailBean email = emailMapper.selectById(inboxBean.getEmailId());
        email.setSender(emMapper.selectById(email.getSenderId()));

        return email;
    }

    @Override
    public void del(Integer inboxId) {
        inboxMapper.deleteById(inboxId);
    }
}
